package name.sraynal.coodiary.file.creator;

import java.io.File;
import java.io.IOException;
import java.util.List;

import name.sraynal.coodiary.storage.Quote;

public abstract class PageCreator {
	public abstract void createPage(String type, List<Quote> quotesList,
							int pos, int pageNumber, File outputDir) throws IOException;
	
	/**
	 * create links table
	 * @param pos
	 * @param pageNumber
	 * @param writer
	 * @throws IOException
	 */
	protected String getLinksTable(int pos, int pageNumber) {
		// Create links' table
		StringBuffer buffer = new StringBuffer();
		buffer.append("<table width=\"100%\">\n<tr>\n<td width=\"25%\"></td>\n")
		// add home
			  .append("<td>\n<a href=\"../index.htm\" id=\"home\">home</a>\n");
		// add prev
		if (pos == 0) {
			buffer.append("<a id=\"previous\" disable=\"true\">prev<a>\n");
		} else {
			buffer.append("<a id=\"previous\" href=\"page").append(new Integer(pos - 1).toString())
				  .append (".htm\">prev<a>\n");
		}
		// add next
		if (pos == pageNumber -1) {
			buffer.append("<a id=\"next\" disable=\"true\">next<a>\n");
		} else {
			buffer.append("<a id=\"next\" href=\"page").append(new Integer(pos + 1).toString())
			.append (".htm\">next<a>\n");
		}
		
		for (int i = 0;i < pageNumber;i++) {
			if (i == pos) {
				buffer.append("<a disabled=\"true\"> " + i +"</a>\n");
			} else {
				buffer.append("<a href=\"page" + i + ".htm\" id=\"page" + i + "\" >" + i + "</a>\n");
			}
		}
		buffer.append("</td><td width=\"25%\"></td>\n</tr>\n</table>\n<br>\n");
		return buffer.toString();
	}
}
